//	ID : pallab81
// 	PROG : 11733
// 	LANG : C++
// 	2011-09-12-07.28.53 Monday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
const int inf = (int)1e6;
int root[ inf+10 ];
int rank[ inf+10 ];
inline void _Set(){
    fo(i,0,inf){
        root[i]=i;
        rank[i]=0;
    }
}
inline int _Find(int x){
    if( x!= root[x] ){
        root[x] = _Find(root[x]);
    }
return root[x];
}
inline void _Union(int x, int y){
    int rx = _Find(x);
    int ry = _Find(y);

    if( rank[rx] > rank[ry] ){
        root[ry] = rx;
    }
    else{
        root[rx] = ry;
    }
    if( rank[rx]==rank[ry] ){
        rank[ry]+=1;
    }
}
int node,nedge,air_cost,k;
struct T{
    int x,y,cc;
    T( int x_, int y_, int cc_):
    x(x_),y(y_),cc(cc_){;}
};
inline bool cmp(T A, T B){
    return A.cc < B.cc ;
}
vector< T > edges;
inline void Read(){
    CI(node);
    CI(nedge);
    CI(air_cost);
    edges.clear();
    int x,y,cc;
    fo(i,0,nedge){
        CI(x);CI(y);CI(cc);
        edges.pb( T(x,y,cc) );
    }
}
inline void Proc(){
    sort(edges.begin(),edges.end(), cmp);
    _Set();
    int total=0;
    int tport=0;
    for(int i=0,j=0; i<nedge && j<node-1 ; ++i){
            int x = edges[i].x;
            int y = edges[i].y;
            int cc = edges[i].cc;

            if( cc<air_cost && _Find(x)!=_Find(y) ){
                _Union(x,y);
                total+=cc;
                ++j;
            }
    }
    for(int i=1; i<=node; ++i){
        if( _Find(i)==i ){
            total+=air_cost;
            ++tport;
           //cout<<i<<" "<<_Find(i)<<"\n";wait(.3);
        }
    }
    printf("Case #%d: %d %d\n",k,total,tport);
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif

    int cases=1;
    for( CI(cases),k=1 ; cases ; --cases,++k ){
        Read();
        Proc();
    }

return 0;
}
